<div class="row-fluid">
	<div class="span12">
		<ul class="breadcrumb">
			<li>
				<a href="index.php">
					<i class="radmin-icon radmin-home"></i>
					<?php echo t('page', 'Dashboard'); ?>
				</a>
				<span class="divider">/</span>
			</li>
			<li>
				<a href="backups.php">
					<i class="radmin-icon radmin-cabinet"></i>
					<?php echo t('page', 'Backups'); ?>
				</a>
				<span class="divider">/</span>
			</li>
			<li class="active">
				<i class="radmin-icon radmin-drawer-2"></i>
				<?php echo t('page', 'Backup Locations'); ?>
			</li>
		</ul>
	</div>
</div>

<div class="row-fluid">
	<div class="span9">
		<h4 class="title"><?php $this->widget('application.components.mywidgets.WikiHelp', array('wiki' => 'backup_locations')); ?> <?php echo t('page', 'Backup Locations'); ?></h4>
		<div class="squiggly-border"></div>
		
		<?php $this->widget('zii.widgets.grid.CGridView', array(
			'id' => 'backuplocations_grid',
			'summaryText' => '',
			'dataProvider' => $backupLocation->search(),
			'columns' => array(
				array(
					'header' => 'Id',
					'value' => '$data->id_backup_locations',
					'headerHtmlOptions' => array('class' => 'hide'),
					'htmlOptions' => array('class' => 'hide id_backup_locations')
				),
				/*array(
					'header' => '',
					'type' => 'raw',
					'value' => 'CHtml::checkBox("backuplocations[checked][]", false, array("class" => "backuplocations_check"))'
				),*/
				array(
					'header' => t('page', 'Name'),
                    'value' => '$data->name',
					'htmlOptions' => array('class' => 'name'),
					'headerHtmlOptions' => array('class' => 'name_sort'),
					'name' => 'username_sort',
					'sortable' => true
				),
				array(
					'header' => t('page', 'Protocol'),
                    'value' => '$data->protocol',
					'htmlOptions' => array('class' => 'protocol'),
					'headerHtmlOptions' => array('class' => 'protocol_sort'),
					'name' => 'protocol_sort',
					'sortable' => true
				),
				array(
					'header' => t('page', 'Server'),
					'value' => '$data->server',
					'htmlOptions' => array('class' => 'server'),
					'headerHtmlOptions' => array('class' => 'server_sort'),
					'name' => 'server_sort',
					'sortable' => true
				),
				array(
					'header' => t('page', 'Username'),
					'value' => '$data->username',
					'headerHtmlOptions' => array('class' => 'username_sort'),
					'htmlOptions' => array('class' => 'username'),
					'name' => 'username_sort',
					'sortable' => true
				),
				array(
					'header' => t('page', 'Port'),
					'type' => 'raw',
					'value' => '$data->port',
					'headerHtmlOptions' => array('class' => 'port_sort'),
					'htmlOptions' => array('class' => 'port'),
					'name' => 'port_sort',
					'sortable' => true
				),
				array(
					'header' => t('page', 'Directory'),
					'type' => 'raw',
					'value' => '$data->directory',
					'headerHtmlOptions' => array('class' => 'directory_sort'),
					'htmlOptions' => array('class' => 'directory'),
					'name' => 'directory_sort',
					'sortable' => true
				),
				array(
					'header' => t('page', 'Action'),
					'type' => 'raw',
					'value' => '$data->renderListActionButtons()'
				)
			),
			'itemsCssClass' => 'table table-index table-striped',
			'pagerCssClass' => 'pagination pagination-right',
			'pager' => array(
				'class' => 'LinkPager',
			),
			'htmlOptions' => array(
				'class' => ''
			)
		));?>
		
		<script>
			$(document).ready(function(){
//				$('#backuplocations_grid .pagination').before($('.pull-left'));
//				$('.pull-left').after('<br /><br />');
				
				var sort = <?php echo json_encode($sort); ?>;
				sort = sort.split('.');
				if(sort[1] == 'desc'){
					var arrow = $('<i class="icon-arrow-down hidden-phone"></i>');
				}else{
					var arrow = $('<i class="icon-arrow-up hidden-phone"></i>');
				}
				$('#backuplocations_grid th.'+sort[0]).append(arrow);				
			});

		</script>
	</div>
	
	<?php $this->renderPartial('forms/_add', array('backupLocationsAddForm' => $backupLocationsAddForm)); ?>
	<?php $this->renderPartial('forms/_edit', array('backupLocationsEditForm' => $backupLocationsEditForm)); ?>

	<script>
		$(document).ready(function(){
			$('#backuplocations_grid .backuplocation_edit').live('click', function(){
				var id_backup_locations = $(this).parents('tr').find('.id_backup_locations').text();
				$('.backuplocation_edit-line').removeClass('backuplocation_edit-line');
				$(this).parents('tr').addClass('backuplocation_edit-line');
				$.ajax({
					url: <?php echo json_encode(url('backup/location/detail')); ?>,
					type: 'get',
					data: {id_backup_locations: id_backup_locations},
					success: function(detail){
						$('#backuplocation-edit-form .fields').val('');
						$.each(detail, function(key, value){
							if($('#backuplocation-edit-form #BackupLocationsEditForm_'+key)){
								$('#backuplocation-edit-form #BackupLocationsEditForm_'+key).val(value);
							}
						});
						$('#BackupLocationsEditForm_protocol').change();
						
						$('#backuplocation-add-block').fadeOut(function(){
							$('#backuplocation-edit-block').fadeIn();
						});
					},
					dataType: 'json'
				});
				
			});
			
			$('#backuplocations_grid .backuplocation_delete').live('click', function(){
				$(this).parents('.btn-group').find('.actions').hide();
				$(this).parents('.btn-group').find('.delete_confirm_btn').show();
			});
			$('#backuplocations_grid .delete_cancel').live('click', function(){
				$(this).parents('.btn-group').find('.actions').show();
				$(this).parents('.btn-group').find('.delete_confirm_btn').hide();
			});
			$('#backuplocations_grid .delete_confirm').live('click', function(){
				var obj = $(this);
				$(this).parents('.btn-group').find('button.actions').attr('data-loading-text', 'deleting').button('loading');
				var id_backup_locations = $(this).parents('tr').find('.id_backup_locations').text();
				$.ajax({
					url: '<?php echo url('backup/location/delete'); ?>',
					type: 'post',
					data: {id_backup_locations: id_backup_locations},
					success: function(ret){
						obj.parents('.btn-group').find('button.actions').button('reset');
						if(ret.result){
							obj.parents('tr').remove();
						}else{
							$("#account_list_error_info").blink({
								"beforeCall": function(){
									$("#account_list_error_info .content").html("");
									$.each(ret["errors"], function(attrName, error){
										$(error).each(function(k, e){
											var p = $("<p />").addClass("text-error").append(attrName+": "+e);
											$("#account_list_error_info .content").append(p);
										});
									});
								}
							});
						}
						obj.parents('.btn-group').find('.delete_cancel').click();
					},
					dataType: 'json'
				});
			});
		});

		$('#switch-backuplocation-add-btn').click(function(){
			$('#backuplocation-edit-block').fadeOut(function(){
				$('#backuplocation-add-block').fadeIn();
			});
		});
	</script>
</div>